﻿@model Sysgeprava.Entities.BOVINO

@{
    ViewBag.Title = "EDITAR";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<link href="~/Content/links/bootstrap-combined.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" media="screen"
      href="~/Content/links/bootstrap-datetimepicker.min.css">

<link rel="stylesheet" type="text/css" media="all" href="~/Content/desing.css">
<script src="~/Scripts/jquery-1.9.1.min.js"></script>

<link rel="stylesheet" href="~/Content/links/jquery-ui.css" />
<script src="~/Content/links/jquery-1.9.1.js"></script>
<script src="~/Content/links/jquery-ui.js"></script>

@{
    var message = TempData["AlertMessage"] ?? string.Empty;
}

<script type="text/javascript">
    var message = '@message';
    if (message) {
        alert(message).alert;
    }
</script>

<div class="float-center" id="panel_titulo">
   <img src="~/Images/titulos/mttoBovino.png" alt="mttoBovino" height="70" width="400"/>
</div>

<h2></h2>


@using (Html.BeginForm("Edit", "Bovino", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>BOVINO</legend>

        <div id="generalBovino">
            @Html.HiddenFor(model => model.Id)

            <div class="tabs">
                <ul class="tab-links">
                    <li class="active"><a href="#tab1">Datos Generales</a></li>
                    <li><a href="#tab2">Datos Compra</a></li>
                    <li><a href="#tab3">Foto Bovino</a></li>
                </ul>

                <div class="tab-content">
                    <div id="tab1" class="tab active">
                        <div style="float:left;width:30%;">
                            <b>Compra: </b>
                            @*<div class="editor-field">
                                @Html.EditorFor(model => model.IndComp)
                            </div>*@
                                <input type="checkbox" id="IndComp" name="IndComp" onclick="habtCompra(this.checked);" />
                            <script type="text/javascript">
                                var id = $("#Id").val();
                                $.ajax({
                                    url: "/Bovino/GetChecks?id=" + id + "&cod=" + 2,
                                    dataType: "json",
                                    success: function (data) {
                                        if (data.chkComp != null && data.chkComp == true) {
                                            document.getElementById("IndComp").checked = true;

                                            document.getElementById("NomVendedor").disabled = false;
                                            document.getElementById("FecCompra").disabled = false;
                                            document.getElementById("PrecComp").disabled = false;
                                            document.getElementById("LugComp").disabled = false;
                                            document.getElementById("icoFecha").style.visibility = "visible";
                                            document.getElementById("IndComp").value = "True";
                                            document.getElementById("BovMadre").disabled = true;
                                        }
                                        if (data.chkComp != null && data.chkComp == false) {
                                            document.getElementById("IndComp").checked = false;

                                            document.getElementById("NomVendedor").disabled = true;
                                            document.getElementById("NomVendedor").value = "";
                                            document.getElementById("FecCompra").disabled = true;
                                            document.getElementById("FecCompra").value = "";
                                            document.getElementById("icoFecha").style.visibility = "hidden";
                                            document.getElementById("PrecComp").disabled = true;
                                            document.getElementById("PrecComp").value = "";
                                            document.getElementById("LugComp").disabled = true;
                                            document.getElementById("LugComp").value = "";
                                            document.getElementById("IndComp").value = "False";
                                            document.getElementById("BovMadre").disabled = false;
                                        }
                                    }
                                });

                                function habtCompra(value) {

                                    if (value == false) {
                                        document.getElementById("NomVendedor").disabled = true;
                                        document.getElementById("NomVendedor").value = "";
                                        document.getElementById("FecCompra").disabled = true;
                                        document.getElementById("FecCompra").value = "";
                                        document.getElementById("icoFecha").style.visibility = "hidden";
                                        document.getElementById("PrecComp").disabled = true;
                                        document.getElementById("PrecComp").value = "";
                                        document.getElementById("LugComp").disabled = true;
                                        document.getElementById("LugComp").value = "";
                                        document.getElementById("IndComp").value = "False";
                                        document.getElementById("BovMadre").disabled = false;
                                        document.getElementById("BovMadre").value = "";
                                    }
                                    else if (value == true) {
                                        document.getElementById("NomVendedor").disabled = false;
                                        document.getElementById("FecCompra").disabled = false;
                                        document.getElementById("PrecComp").disabled = false;
                                        document.getElementById("LugComp").disabled = false;
                                        document.getElementById("icoFecha").style.visibility = "visible";
                                        document.getElementById("IndComp").value = "True";
                                        document.getElementById("BovMadre").disabled = true;

                                        var id = $("#Id").val();
                                        $.ajax({
                                            url: "/Bovino/GetBovinoMadreByCompra?id=" + 1,
                                            dataType: "json",
                                            success: function (data) {
                                                if (data.existe != null) {
                                                    document.getElementById("BovMadre").value = data.bovMadre;
                                                    document.getElementById("IdBovMadre").value = data.idBovMadre;
                                                }
                                            }
                                        });
                                    }
                                }
                            </script>
                            <h2></h2>
                            <b>Vaca Madre: </b>
                            <div class="editor-field">
                                @Html.TextBox("IdBovMadre")
                                <input type="text" id="BovMadre" required />
                            </div>
                            <script type="text/javascript">
                                $("#IdBovMadre").hide();

                                $("#BovMadre").autocomplete({
                                    source: function (request, response) {
                                        var customer = new Array();
                                        $.ajax({
                                            async: false,
                                            cache: false,
                                            type: "POST",
                                            url: "@(Url.Action("GetAllBovinoByCriterio", "Bovino"))",
                                            data: { "term": request.term },
                                            success: function (data) {
                                                response($.map(data, function (item) {
                                                    return { label: item.nomCompleto, id: item.id, nom: item.label };
                                                }));
                                            }
                                        });
                                    },
                                    select: function (event, ui) {
                                        $("#IdBovMadre").val(ui.item.id);
                                        $("#BovMadre").val(ui.item.nom);
                                        return false;
                                    }
                                });

                                var id = $("#Id").val();
                                $.ajax({
                                    url: "/Bovino/GetBovinoMadre?id=" + id,
                                    dataType: "json",
                                    success: function (data) {
                                        if (data.existe != null) {
                                            document.getElementById("BovMadre").value = data.bovMadre;
                                        }
                                    }
                                });
                            </script>
                            <b>N° Arete: </b>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.NroArete)
                                @Html.ValidationMessageFor(model => model.NroArete)
                            </div>
                            <b>Nombre: </b>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.Nombre)
                                @Html.ValidationMessageFor(model => model.Nombre)
                            </div>
                            <b>Fecha Nacimiento: </b>
                            @*<div class="editor-field">
                                @Html.EditorFor(model => model.FecNac)
                                @Html.ValidationMessageFor(model => model.FecNac)
                            </div>*@
                            <div id="timeNac" class="input-append">
                                <input data-format="dd/MM/yyyy" type="text" id="FecNac" name="FecNac"/>
                                <span class="add-on">
                                    <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
                                </span>
                            </div>
                            <script type="text/javascript">
                                var id = $("#Id").val();
                                $.ajax({
                                    url: "/Bovino/GetFechas?id=" + id + "&cod="+1,
                                    dataType: "json",
                                    success: function (data) {
                                        if (data.fecNac != null) {
                                            document.getElementById("FecNac").value = data.fecNac;
                                        }
                                        if (data.fecComp == "1/01/0001")
                                        {
                                            document.getElementById("FecNac").value = "";
                                        }
                                    }
                                });
                            </script>
                        </div>

                        <div style="float:right; width:30%">
                            <b>Etapa: </b>
                            <div class="editor-field">
                                 @Html.DropDownList("IdEtapa")
                            </div>
                            <b>Peso Actual: </b>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.PesoAct)
                                @Html.ValidationMessageFor(model => model.PesoAct)
                            </div>
                            <b>Primerisa: </b>
                            @*<div class="editor-field">
                                @Html.EditorFor(model => model.IndPrimerisa)
                                @Html.ValidationMessageFor(model => model.IndPrimerisa)
                            </div>*@
                                <input type="checkbox" id="IndPrimerisa" name="IndPrimerisa" onclick="habtPrimerisa(this.checked);" />
                            <script type="text/javascript">
                                var id = $("#Id").val();
                                $.ajax({
                                    url: "/Bovino/GetChecks?id=" + id + "&cod=" + 1,
                                    dataType: "json",
                                    success: function (data) {
                                        if (data.chkPrim != null && data.chkPrim == true) {
                                            document.getElementById("IndPrimerisa").checked = true;
                                            document.getElementById("CantPartos").disabled = true;
                                            document.getElementById("CantPartos").value = "";
                                            document.getElementById("IndPrimerisa").value = "True";
                                        }
                                        if (data.chkPrim != null && data.chkPrim == false) {
                                            document.getElementById("IndPrimerisa").checked = false;
                                            document.getElementById("CantPartos").disabled = false;
                                            document.getElementById("IndPrimerisa").value = "False";
                                        }
                                    }
                                });

                                function habtPrimerisa(value) {

                                    if (value == true) {
                                        document.getElementById("CantPartos").disabled = true;
                                        document.getElementById("CantPartos").value = "";
                                        document.getElementById("IndPrimerisa").value = "True";
                                    }
                                    else if (value == false) {
                                        document.getElementById("CantPartos").disabled = false;
                                        document.getElementById("IndPrimerisa").value = "False";
                                    }
                                }
                            </script>
                            <h2></h2>
                            <b>Cantidad Partos: </b>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.CantPartos)
                                @Html.ValidationMessageFor(model => model.CantPartos)
                            </div>
                        </div>

                        <div style="width:30%;margin:auto;">
                            <b>Lugar Nacimiento: </b>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.LugNac)
                                @Html.ValidationMessageFor(model => model.LugNac)
                            </div>
                            <b>N° Registro: </b>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.NroRegistro)
                                @Html.ValidationMessageFor(model => model.NroRegistro)
                            </div>
                            <b>Sexo: </b>
                            <div class="editor-field">
                                 @Html.DropDownList("IdSexo")
                            </div>
                            <b>Raza: </b>
                            <div class="editor-field">
                                 @Html.DropDownList("IdRaza")
                            </div>
                        </div>
                    </div>

                    <div id="tab2" class="tab">
                        <b>Nombre Vendedor: </b>
                        <div class="editor-field">
                            @Html.EditorFor(model => model.NomVendedor)
                            @Html.ValidationMessageFor(model => model.NomVendedor)
                        </div>
                        <b>Fecha Compra: </b>
                        @*<div class="editor-field">
                            @Html.EditorFor(model => model.FecCompra)
                            @Html.ValidationMessageFor(model => model.FecCompra)
                        </div>*@
                        <div id="timeCompra" class="input-append">
                            <input data-format="dd/MM/yyyy" type="text" id="FecCompra" name="FecCompra"/>
                            <span class="add-on" id="icoFecha" >
                                <i data-time-icon="icon-time" data-date-icon="icon-calendar" ></i>
                            </span>
                        </div>
                        <script type="text/javascript">
                            var id = $("#Id").val();
                            $.ajax({
                                url: "/Bovino/GetFechas?id=" + id + "&cod=" + 2,
                                dataType: "json",
                                success: function (data) {
                                    if (data.fecComp != null) {
                                        document.getElementById("FecCompra").value = data.fecComp;
                                    }
                                    if (data.fecComp == "1/01/0001")
                                    {
                                        document.getElementById("FecCompra").value = "";
                                    } 
                                }
                            });
                            </script>
                        <b>Precio Compra: </b>
                        <div class="editor-field">
                            @Html.EditorFor(model => model.PrecComp)
                            @Html.ValidationMessageFor(model => model.PrecComp)
                        </div>
                        <b>Lugar Compra: </b>
                        <div class="editor-field">
                            @Html.EditorFor(model => model.LugComp)
                            @Html.ValidationMessageFor(model => model.LugComp)
                        </div>
                    </div>

                    <div id="tab3" class="tab">
                        <div style="float:right; margin-right:250px; border:solid;"> 
                            <img id="imgObt" width="250" height="250" src="@Url.Action("GetImagen", "Bovino", new { Model.Id })" /> 
                            <output id="list"></output>
                        </div> 
                        <div class="editor-field">
                            <input type="file" title="Seleccione foto" name="image" id="files" accept=".jpg, .png" />
                        </div>
                    </div>                   
                </div>
            </div>
        </div>

        <h2></h2>
        <p>
            <button type="submit" name="btnGuardar" value="Edit"><img src="~/Images/botones/save.png"></button>
            <button onclick="location.href='@Url.Action("Index")';return false;" ><img src="~/Images/botones/return.png"></button>
        </p>
    </fieldset>
}

@*<div>
    @Html.ActionLink("Back to List", "Index")
</div>*@

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")

         @*-----obtener date time picker-------*@

    <script type="text/javascript"
     src="~/Content/links/jquery.min.js">
    </script> 
    <script type="text/javascript"
     src="~/Content/links/bootstrap.min.js">
    </script>
    <script type="text/javascript"
     src="~/Content/links/bootstrap-datetimepicker.min.js">
    </script>
    <script type="text/javascript"
     src="~/Content/links/bootstrap-datetimepicker.pt-BR.js">
    </script>
    <script type="text/javascript">

        $(function () {
            $('#timeNac').datetimepicker({
                pickTime: false
            });
        });

        $(function () {
            $('#timeCompra').datetimepicker({
                pickTime: false
            });
        });
        /*-----------------------------------------------------------------------------------------------*/

    </script>
}
